export const requestUrls = (urls = [], maxLen = 1) => {
  return new Promise((resolve, reject) => {
    const len = urls.length;
    const results = new Array(len).fill(false);
    let count = 0;

    while (count < maxLen) {
      next();
    }
    function next() {
      const current = count++;
      if (current >= len) {
        // 收集完结果后才返回
        !results.includes(false) && resolve(results);
        return;
      }
      const url = urls[current];
      fetch(url)
        .then((data) => {
          results[current] = data;
          if (current < len) {
            next();
          }
        })
        .catch((err) => {
          results[current] = err;
          if (current < len) {
            next();
          }
        });
    }
  });
};
